﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MvcWebRole1.Models;

namespace MvcWebRole1.Controllers
{
    public class OrderController : ApiController
    {
        // GET api/default1/5
        public string Get(int id)
        {
            return "value";
        }

        public IEnumerable<OrderModel> GetAllProducts()
        {
            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand("SELECT * FROM UserOrder", conn))
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    List<OrderModel> orderModelList = new List<OrderModel>();
                    while (reader.Read())
                    {
                        orderModelList.Add(new OrderModel() { ID = reader.GetInt32(0).ToString(), Name = reader.GetString(1) });
                        //Console.WriteLine("{0} {1} {2}",
                        //reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
                        //ViewBag.Message += @"\n" +  + ": " + reader.GetString(1);
                    }
                    return orderModelList;
                }                
            }            
        }

        // POST api/default1
        public void Post(string value)
        {
        }

        // PUT api/default1/5
        public void Put(int id, string value)
        {
        }

        // DELETE api/default1/5
        public void Delete(int id)
        {
        }
    }
}
